package org.mparts.client.mvp;

import org.mparts.client.utils.Utils;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.user.client.Window;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;

public class MpartsActivityMapper implements ActivityMapper {
//	private ClientFactory clientFactory;

//	public MpartsActivityMapper(ClientFactory clientFactory) {
//		super();
//		this.clientFactory = clientFactory;
//	}
//
//	@Override
//	public Activity getActivity(Place place) {
//		if (place instanceof MainPlace) {
//			return new MainActivity(clientFactory);
//		}
//		return null;
//	}
//

	private EventBus eventBus;
	private PlaceController placeController;
	
	@Inject
	public MpartsActivityMapper(EventBus eventBus, PlaceController placeController) {
		super();
		this.eventBus = eventBus;
		this.placeController = placeController;
	}
	
	@Override
	public Activity getActivity(Place place) {
		if (place instanceof ActivityPlace) {
			Activity activity = ((ActivityPlace) place).getActivity();
			Log.debug("push GA place: " + ((ActivityPlace) place).getHistoryToken());
			Utils.recordAnalyticsHit(((ActivityPlace) place).getHistoryToken());
            return activity;
        }

        return null;
		
	}
}
